﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenChart.Entities;
using OpenChart.DrawChart;

namespace OpenChart
{
    public partial class Chart : UserControl
    {
        AbsDrawingChart _drawChart;
        ChartArea _chart = new ChartArea();

        public Chart()
        {
            InitializeComponent();
            this.Load += new EventHandler(Chart_Load);
        }

        void Chart_Load(object sender, EventArgs e)
        {
            _drawChart = DrawingChartFactory.Create(this.ChartArea.ChartType);
        }

        /// <summary>
        /// ChartArea
        /// </summary>
        [Browsable(false)]
        public ChartArea ChartArea
        {
            get { return _chart; }
            set { _chart = value; }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.DesignMode == false)
            {
                base.OnPaint(e);
                _drawChart.ChartArea = _chart;
                _drawChart.CanvasHeight = this.Height;
                _drawChart.CanvasWidth = this.Width;
                _drawChart.Graphics = e.Graphics;
                _drawChart.DrawChart();
            }
        }

        private void Chart_SizeChanged(object sender, EventArgs e)
        {
            this.Refresh();
        }
    }
}
